#include<stdio.h>
int main()
{
	long long n;
	scanf("%lld",&n);
	long long k=0;
	scanf("%lld",&k);
	long long arr[n];
	long long count1=0,count2=0;
	for(long long i=0;i<n;i++)
	{
		scanf("%lld",&arr[i]);
	}
	long long max_ji=arr[0];
	long long max_ou=arr[0];
	for(long long i=0;i<n;i++)
	{
		if(arr[i]%2==0&&arr[i]>max_ou)
		{
			max_ou=arr[i];
		}
		if(arr[i]%2!=0&&arr[i]>max_ji)
		{
			max_ji=arr[i];
		}
	}
	long long p1=-1,p2=-1;
	for(long long i=0;i<n;i++)
	{
		if(arr[i]==max_ji)
		{
			p1++;
		}
		if(arr[i]==max_ou)
		{
			p2++;
		}
	}
	for(long long i=0;i<n;i++)
	{
		while(arr[i]!=max_ou&&arr[i]!=max_ji)
		{
			long long m=arr[i];
			for(long long j=1;j<9999;j++)
			{
				arr[i]=m;
				arr[i]=m+j*k;
				if(arr[i]==max_ji)
				{
					count1++;
					break;
				}
				if(arr[i]>max_ji)
				break;
			}
			arr[i]=m;
			break;
		}
			while(arr[i]!=max_ou&&arr[i]!=max_ji)
		{
			long long m=arr[i];
			for(long long j=1;j<9999;j++)
			{
				arr[i]=m;
				arr[i]=m+j*k;
				if(arr[i]==max_ou)
				{
					count2++;
					break;
				}
				if(arr[i]>max_ou)
				break;
			}
			break;
		}
	 }
	 if(count2>count1)
	 printf("%lld",count2+1+p2); 
	 else 
	 printf("%lld",count1+1+p1);
}
